/**
 *  example2.vala
 *
 *  Copyright (c) 2007 INdT (Instituto Nokia de Technologia)
 *                2007 Marcelo Lira dos Santos <setanta@gmail.com>
 *
 *  Author: Marcelo Lira dos Santos <setanta@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA
 */

using GLib;
using Gtk;
using Hildon;

public class Example2 : Hildon.Window
{
    [Widget] protected Entry entry1;
    [Widget] protected Label label1;
    [Widget] protected Label label2;
    [Widget] protected Button button1;

    construct {
        var vbox1 = new VBox(false, 4);
        vbox1.border_width = 4;

        var hbox1 = new HBox(false, 4);

        label1 = new Label("Write something:");
        hbox1.pack_start(label1, false, false, 0);

        entry1 = new Entry();
        entry1.activate += on_entry1_activated;
        hbox1.pack_start(entry1, true, true, 0);

        button1 = new Button.from_stock("gtk-apply");
        button1.clicked += on_button1_clicked;
        hbox1.pack_start(button1, false, false, 0);

        vbox1.pack_start(hbox1, false, true, 0);

        var separator = new HSeparator();
        vbox1.pack_start(separator, false, true, 2);

        label2 = new Label("");
        label2.xalign = 0.0;
        label2.set_line_wrap(true);
        vbox1.pack_start_defaults(label2);

        add (vbox1);

        destroy += Gtk.main_quit;
    }

    void on_button1_clicked (Button button) {
        do_write_message();
    }

    void on_entry1_activated (Entry entry) {
        do_write_message();
    }

    private void do_write_message() {
        label2.set_markup("<b>You've written:</b> " + entry1.text);
    }

    static int main (string[] args) {
        Gtk.init(out args);

        Environment.set_application_name("Sample 2");

        Example2 ex2 = new Example2();

        Hildon.Program program = Hildon.Program.get_instance();
        program.add_window((Hildon.Window) ex2);

        ex2.show_all();

        Gtk.main();

        return 0;
    }
}
